/*
 * @Description:
 * @version:
 * @Author: 尹鹏孝
 * @Date: 2025-03-17 20:51:36
 * @LastEditors: 尹鹏孝
 * @LastEditTime: 2025-03-17 22:33:07
 */
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn,CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { Order } from './order.entity';

export enum PaymentStatus {
    PENDING = 'PENDING',
    COMPLETED = 'COMPLETED',
    FAILED = 'FAILED',
    REFUNDED = 'REFUNDED'
  }

 export enum PaymentMethod {
    ALIPAY = 'ALIPAY',
    WECHAT = 'WECHAT',
    UNIONPAY = 'UNIONPAY',
    BALANCE = 'BALANCE'
}


export enum currencyType{
  CNY = 'CNY',
  USD = 'USD',
  EUR = 'EUR',
  JPY = 'JPY',
  GBP = 'GBP',
  AUD = 'AUD',
  CAD = 'CAD',
  CHF = 'CHF',
  SEK = 'SEK',
  NOK = 'NOK',
  DKK = 'DKK',
  HKD = 'HKD',
  SGD = 'SGD',
  MYR = 'MYR',
  THB = 'THB',
  PHP = 'PHP',
  VND = 'VND',
  KRW = 'KRW',
  TWD = 'TWD',
  BRL = 'BRL',
  RUB = 'RUB',
  IDR = 'IDR',
  INR = 'INR',
  MXN = 'MXN',
  PKR = 'PKR',
  BDT = 'BDT',
  NGN = 'NGN',
  ZAR = 'ZAR',
  AED = 'AED',
  SAR = 'SAR',
  QAR = 'QAR',
  KWD = 'KWD',
  OMR = 'OMR',
  LKR = 'LKR',
  JOD = 'JOD',
  TND = 'TND',
  LYD = 'LYD',
  EGP = 'EGP',
  YER = 'YER',
  KES = 'KES',
  UGX = 'UGX',
  GHS = 'GHS',
  TZS = 'TZS',
  MUR = 'MUR',
  BHD = 'BHD',
  KMF = 'KMF',
  RWF = 'RWF',
  BIF = 'BIF',
  XAF = 'XAF',
  XOF = 'XOF',
  CDF = 'CDF',
  XPF = 'XPF',
  ANG = 'ANG',
  MGA = 'MGA',

}

@Entity('payment')
export class Payment {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'decimal', precision: 12, scale: 2 })
  amount: number;

  @Column({ length: 3 })
  currency: string;

  // @Column({type: 'string',unique:true})
  // paymentNo: string;
  @Column({ nullable: true,type: 'varchar', length: 100, unique: true })
  paymentNo: string;
  @Column({
    type: 'enum',
    enum: PaymentStatus,
    default: PaymentStatus.PENDING
  })
  status: PaymentStatus;

  @Column({ unique: true })
  transactionId: string;

  @Column({
    type: 'enum',
    enum: PaymentMethod
  })
  paymentMethod: PaymentMethod;

  // @ManyToOne(() => Order, order => order.payments)
  @JoinColumn({ name: 'order' })
  order: Order;

  @Column({ name: 'orderId' })
  orderId: number;
  @Column({ name: 'userId' })
  userId: number;
  // @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  @CreateDateColumn()
  createdAt: Date;

  // @Column({ type: 'timestamp', nullable: true })
  @UpdateDateColumn()
  updatedAt: Date;

  @Column({ type: 'timestamp', nullable: false, })
  @CreateDateColumn({ name: 'paidAt', type: 'timestamp', default: () => 'NOW()' })
  paidAt: Date;
}